const createReminderMessageService = () =>
  import("~/services/common-service/reminder-message.service");
import { ReminderMessageType } from "~/utils/reminder.service";


export default {
  namespaced: true,
  state: {
    unReadCount: 0,
    legalUnReadCount: 0, // 法务未读消息数量
    taskList: [],
    messageBoxVisible: false,
    messageLegalBoxVisible: false,
    breadCrumbPathList: [], // 面包屑层级
    isMessageShow: false
  },
  mutations: {
    updateMessageBoxVisible(state, visible) {
      state.messageBoxVisible = visible;
    },

    updateLegalMessageBoxVisible(state, visible) {
      state.messageLegalBoxVisible = visible;
    },

    updateTaskList(state, list) {
      state.taskList = list;
    },
    updatedIsMessageShow(state, visible) {
      state.isMessageShow = visible;
    },
    /**
     * 更新未读消息数
     * @param state
     * @param count
     */
    updateUnReadCount(state, count) {
      state.unReadCount = count;
    },

    updateLegalUnReadCount(state, count) {
      state.legalUnReadCount = count;
    },

    getBreadcrumbPathList(state, matchedRouter) {
      console.log("bread", matchedRouter);
    }
  },
  actions: {
    /**
     * 查询未读消息树
     */
    async updateUnReadCount({ commit, rootState }) {
      const { ReminderMessageService } = await createReminderMessageService();
      if (rootState.userToken) {
        ReminderMessageService.getInstance()
          .getUnReadCount()
          .subscribe(count => {
            commit("updateUnReadCount", count);
          });
        commit("updateUnReadCount", 0);
      }
    },

    async updateLegalUnReadCount({ commit, rootState }) {
      const { ReminderMessageService } = await createReminderMessageService();
      if (rootState.userToken) {
        ReminderMessageService.getInstance()
          .getUnReadCount(ReminderMessageType.LegalTaskMessage)
          .subscribe(count => {
            commit("updateLegalUnReadCount", count);
          });
        commit("updateLegalUnReadCount", 0);
      }
    }
  }
};
